package com.tl.khadmin.controller;
 
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tl.khadmin.bean.Warehouse;
import com.tl.khadmin.bean.dto.ProductListDto;
import com.tl.khadmin.bean.ProductType;
import com.tl.khadmin.bean.Staff;
import com.tl.khadmin.page.Page; 
import com.tl.khadmin.service.ProductTypeIService;
import com.tl.khadmin.service.WareHouseIService;
import com.tl.khadmin.util.CommonUtil;

/**
 * 仓库控制器
 * @author 123
 */
@RestController
@RequestMapping(value = "/warehouse")
public class WareHouseController {
	
	@Resource
	private WareHouseIService wareHouseService; 
	
	/** 
	 * @param param warehouseName 
	 * @param param enable：1启用，2禁用
	 * @return
	 */
	@RequestMapping(value="/list") 
	public Map<String, List<Warehouse>> listWarehouse(HttpSession session, @RequestParam Map<String ,Object> param){
		return CommonUtil.returnResultCodeJson("list", wareHouseService.listWarehouse(session, param));
	}

	@RequestMapping(value = "/showbypage")
	public Map<String, Page<Warehouse>> showWarehouseByPage(HttpSession session, @RequestParam Map<String, Object> params) { 
		Integer pageNum = Integer.parseInt(params.get("pageNum").toString());
		Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
		return CommonUtil.returnResultCodeJson("result", wareHouseService.showWarehouseByPage(session, pageNum, pageSize, params));
	}
	
	@RequestMapping(value = "/save")
	@ResponseBody
	public String saveWarehouse(HttpSession session, @Valid Warehouse warehouse, BindingResult br) {
		return wareHouseService.saveWarehouse(session, warehouse);
	}
	
	@RequestMapping(value = "/update")
	@ResponseBody
	public String updateWarehouse( @Valid Warehouse Warehouse, BindingResult br) {
		return wareHouseService.updateWarehouse(Warehouse);
	}

	@RequestMapping(value = "/deletebyids")
	@ResponseBody
	public String deleteByIds(String ids) {
		if(StringUtils.isBlank(ids)){
			return CommonUtil.returnMapResultByRows(0, "","未勾选");
		}
		return wareHouseService.deleteByIds(ids);
	}

	@RequestMapping(value = "/querybyid")
	@ResponseBody
	public Map<String, Object> queryWarehouseById(Integer id) {
		if(id==null){
			return null;
		}
		return wareHouseService.queryWarehouseById(id);
	}
	
}
